package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoomDto;
import com.zzyl.service.RoomService;
import com.zzyl.vo.RoomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/room")
@Api(tags = "房间管理")
@Slf4j
public class RoomController extends BaseController {
    @Autowired
    private RoomService roomService;

//    @PostMapping("/add")
//    @ApiOperation("添加房间")
//    public ResponseResult addRoom(@RequestBody RoomDto roomDto) {
//        return toAjax(roomService.addRoom(roomDto));
//    }

    /**
     * 添加房间
     * @param roomDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加房间")
    public ResponseResult addRoom(@RequestBody @ApiParam("添加房间信息") RoomDto roomDto){
        log.info("添加房间方法执行了 添加信息为：{}",roomDto.toString());
        int rows =  roomService.addRoom(roomDto);
        return toAjax(rows);
    }

//    @DeleteMapping("/delete/{id}")
//    @ApiOperation("删除房间")
//    public ResponseResult deleteRoom(@PathVariable Long id) {
//        return toAjax(roomService.deleteRoom(id));
//    }

    /**
     * 删除房间
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除房间")
    public ResponseResult deleteRoom(@PathVariable @ApiParam("删除房间id") Long id){
        int rows = roomService.deleteRoom(id);
        return toAjax(rows);
    }

//    @PutMapping("/update")
//    @ApiOperation("更新房间")
//    public ResponseResult updateRoom(@RequestBody RoomDto roomDto) {
//        return toAjax(roomService.updateRoom(roomDto));
//    }
    @PutMapping("/update")
    @ApiOperation("更新房间")
    public ResponseResult updateRoomById(@RequestBody @ApiParam("更新房间信息") RoomDto roomDto){
        log.info("修改房间方法执行力：{}",roomDto.toString());
        int rows = roomService.updateroom(roomDto);
        return toAjax(rows);
    }

//    @GetMapping("/get/{id}")
//    @ApiOperation("获取房间")
//    public ResponseResult<RoomVo> getRoom(@PathVariable Long id) {
//        return success(roomService.getRoom(id));
//    }

    /**
     * 根据id查询指定房间
     * @param id
     * @return
     */
    @ApiParam("查询指定房间")
    @GetMapping("/get/{id}")
    public ResponseResult<RoomVo> getRoom(@PathVariable @ApiParam("获取房间id") long id){
        log.info("查询指定房间执行了：{}",id);
        RoomVo roomVo = roomService.getroomByid(id);
        return success(roomVo);
    }

//    @GetMapping("/getAllVo")
//    @ApiOperation("获取所有房间（所有楼层）")
//    public ResponseResult<List<RoomVo>> getAllRoomVos() {
//        return success(roomService.getAllRoomVos());
//    }


    @GetMapping("/getAllVo")
    @ApiOperation("查询所有房间")
    public ResponseResult<List<RoomVo>> getRoomList(){
        log.info("查询所有房间执行了");
        List<RoomVo> roomVos = roomService.selectAll();
        return success(roomVos);

    }

    @GetMapping("/getRoomsByFloorId/{floorId}")
    @ApiOperation("获取所有房间（入住配置）")
    public ResponseResult<List<RoomVo>> getRoomsByFloorId(@PathVariable Long floorId) {
        return success(roomService.getRoomsByFloorId(floorId));
    }


    @GetMapping("/getRoomsCheckedByFloorId/{floorId}")
    @ApiOperation("获取所有房间（床位房型）")
    public ResponseResult<List<RoomVo>> getRoomsCheckedByFloorId(@PathVariable Long floorId) {
        return success(roomService.getRoomsCheckedByFloorId(floorId));
    }

    @GetMapping("/getRoomsWithNurByFloorId/{floorId}")
    @ApiOperation("获取所有房间（负责老人）")
    public ResponseResult<List<RoomVo>> getRoomsWithNurByFloorId(@PathVariable Long floorId) {
        return success(roomService.getRoomsWithNurByFloorId(floorId));
    }

}
